Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
resolve-pkg
Advanced tools
The resolve-pkg npm package is used to resolve the path of a package regardless of where it is located in the node_modules hierarchy. This is particularly useful in monorepos or when dealing with nested dependencies.
Resolve Package Path
This feature allows you to resolve the absolute path of a package. The code sample demonstrates how to use resolve-pkg to find the path of 'some-package'.
const resolvePkg = require('resolve-pkg');
const packagePath = resolvePkg('some-package');
console.log(packagePath);
Resolve Package Path with CWD
This feature allows you to resolve the package path starting from a specific directory. The code sample shows how to specify a custom current working directory (cwd) for the search.
const resolvePkg = require('resolve-pkg');
const packagePath = resolvePkg('some-package', { cwd: '/path/to/start/search' });
console.log(packagePath);
The 'resolve' package is a dependency resolver that can find the full path to a module from a given starting point. It is more general-purpose compared to resolve-pkg, which is specifically designed for resolving package paths.
The 'pkg-dir' package finds the root directory of a Node.js project or a package. While resolve-pkg focuses on resolving the path to a specific package, pkg-dir is useful for finding the root directory of the current project.
The 'find-up' package searches for a file or directory by walking up parent directories. It is more versatile in terms of finding various types of files, whereas resolve-pkg is specialized in resolving package paths.
Resolve the path of a package regardless of it having an entry point
Some packages like CLI tools and grunt tasks don't have a entry point, like "main": "foo.js"
in package.json, resulting in them not being resolvable by require.resolve()
. Unlike require.resolve()
, this module also resolves packages without an entry point, returns undefined
instead of throwing when the module can't be found, and resolves from process.cwd()
instead __dirname
by default.
$ npm install resolve-pkg
const resolvePkg = require('resolve-pkg');
// $ npm install --save-dev grunt-svgmin
resolvePkg('grunt-svgmin/tasks', {cwd: __dirname});
//=> '/Users/sindresorhus/unicorn/node_modules/grunt-svgmin/tasks'
// Fails here as Grunt tasks usually don't have a defined main entry point
require.resolve('grunt-svgmin/tasks');
//=> Error: Cannot find module 'grunt-svgmin'
Type: string
What you would use in require()
.
Type: string
Default: process.cwd()
Directory to resolve from.
MIT © Sindre Sorhus
FAQs
Resolve the path of a package regardless of it having an entry point
The npm package resolve-pkg receives a total of 1,334,728 weekly downloads. As such, resolve-pkg popularity was classified as popular.
We found that resolve-pkg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.